/**
 * Copyright © 2004-2018 ***.All Rights Reserved.
 */
package com.framework.common.jdbc.interceptor;

import java.io.Serializable;

/**
 * 
 * @version V1.0
 * @author zhoubb
 * @Date 2018-12-04
 * @since JDK 1.7
 */
public class PageParaBean implements Serializable{
	private static final long serialVersionUID = -1988400349801901570L;
	/**
	 * 当前页码
	 */
	private Integer page = 1;
	/**
	 * 每页多少条记录
	 */
	private Integer rows = 10;
	/**
	 * 排序字段
	 */
	private String sort;
	
	/**
	 * 数据库排序字段，如果此字段为空，则取sort为排序字段
	 */
	private String sortName;
	
	/**
	 * 排序顺序 asc desc
	 */
	private String order;
	
	/**
	 * 总计多少条
	 */
	private Integer total = 0;
	
	/**
	 * 是否需要计算总共多少条
	 */
	private boolean countCompute = true;
	
	public PageParaBean() {
	}

	public PageParaBean(Integer page, Integer rows) {
		this.page = page;
		this.rows = rows;
	}

	public Integer getPage() {
		return page;
	}

	public PageParaBean setPage(Integer page) {
		this.page = page;
		return this;
	}

	public Integer getRows() {
		return rows;
	}

	public PageParaBean setRows(Integer rows) {
		this.rows = rows;
		return this;
	}

	public String getSort() {
		return sort;
	}

	public PageParaBean setSort(String sort) {
		this.sort = sort;
		return this;
	}

	public String getOrder() {
		return order;
	}

	public PageParaBean setOrder(String order) {
		this.order = order;
		return this;
	}

	public String getSortName() {
		return sortName;
	}

	public PageParaBean setSortName(String sortName) {
		this.sortName = sortName;
		return this;
	}
	
	public int getOffset() {
		if(page == null || rows == null || page <= 1 || rows <= 0) {
			return 0;
		}
		return (page - 1) * rows;
	}
	
	public int getMaxResults() {
		if(rows != null) {
			return rows;
		}
		return 0;
	}
	
	public boolean enablePaging() {
		if(rows == null) return false;
		return rows >= 0;
	}

	public Integer getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}

	public boolean isCountCompute() {
		return countCompute;
	}

	public void setCountCompute(boolean countCompute) {
		this.countCompute = countCompute;
	}

}
